﻿CREATE PROCEDURE [dbo].[yaf_topic_save](
                @ForumID  INT,
                @Subject  NVARCHAR(128),
                @UserID   INT,
                @Message  NTEXT,
                @Priority SMALLINT,
                @UserName NVARCHAR(50)  = NULL,
                @IP       NVARCHAR(15),
                @PollID   INT  = NULL,
                @Posted   DATETIME  = NULL,
                @Flags    INT)
AS
    BEGIN
        DECLARE  @TopicID INT
        DECLARE  @MessageID INT
        IF @Posted IS NULL
        SET @Posted = Getdate()
        INSERT INTO yaf_Topic
                   (ForumID,
                    Topic,
                    UserID,
                    Posted,
                    Views,
                    Priority,
                    PollID,
                    UserName,
                    NumPosts)
        VALUES     (@ForumID,
                    @Subject,
                    @UserID,
                    @Posted,
                    0,
                    @Priority,
                    @PollID,
                    @UserName,
                    0)
        SET @TopicID = Scope_identity()
        EXEC yaf_message_save
             @TopicID ,
             @UserID ,
             @Message ,
             @UserName ,
             @IP ,
             @Posted ,
             NULL ,
             @Flags ,
             @MessageID OUTPUT
        SELECT TopicID = @TopicID,
               MessageID = @MessageID
    END


